using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace Rest.Http.Authentication
{
    /// <summary>
    /// 
    /// </summary>
    public class BasicAuthentication
    {
        /// <summary>
        /// Returns a basic authorization header
        /// </summary>
        /// <param name="credential"></param>
        /// <returns></returns>
        public static String CreateAuthorizationHeader(NetworkCredential credential)
        {
            return CreateAuthorizationHeader(credential.UserName, 
                credential.Password);
        }

        /// <summary>
        /// Returns a basic authorization header
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static String CreateAuthorizationHeader(String username,
            String password)
        {
            Byte[] credentialBytes = Encoding.ASCII.GetBytes(
                username + ":" + password);

            return String.Format("Authorization: Basic {0}\r\n",
                Convert.ToBase64String(credentialBytes));
        }
    }
}
